package com.apes.framework.plugin.form.parser.element;

import com.apes.framework.plugin.form.parser.node.FormNodeParser;
import com.apes.framework.plugin.filereader.xml.ApesElement;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 功能：流程状态栏解析
 *
 * @author xul
 * @create 2018-04-20 17:10
 */
@Component
public class StatusbarElementParser extends AbstractElementParser {

    /**
     * 可解析的元素列表
     **/
    private final String[] elementNames = {"statusbar"};

    /**
     * 功能：可解析节点域
     */
    @Override
    public String getDomain() {
        return FormNodeParser.domain;
    }

    /**
     * 功能：可解析的元素列表
     */
    @Override
    public String[] getNames() {
        return elementNames;
    }


    /**
     * 功能：解析子节点
     */
    @Override
    protected void parseNestedElements(Map node, Collection<ApesElement> elements) {
        node.put("statusbar", elements.stream()
                .map(new Function<ApesElement, Object>() {
                    @Override
                    public Object apply(ApesElement apesElement) {
                        return apesElement.parse();
                    }
                }).collect(Collectors.toList()));
    }

}
